home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-05-22 | 5.3 KB | 126 lines | [TEXT/MPS ] |
- The Transfer DA is a small desk accessory that adds a Transfer menu
- to any application that supports desk accessories.
-
- When Apple killed the Minifinder, my work habits were shattered. I
- tried Oasis, a Finder substitute, for a while but I didn't like the
- way the working directory was changed by launching a program; that
- is, if I launched, say, Macwrite, and opened a file, the sfget
- dialog came up showing the directory that contained Macwrite, rather
- than the one I had been working in. I had to navigate through
- folders to return to my work files.
-
- Transfer solves that problem. Now, I work on the desktop but when I
- want to switch from one application to another, I use Transfer. The
- working directory is unaffected, and I skip the Finder.
-
- This DA illustrates some interesting programming techniques: it is
- a segmented DA; it does an HFS search of an entire hard disk; it
- uses the iaznotify hook; and it creates resources with TML Pascal (a
- subject which came up in the May Mac Tutor letters column).
-
- How the DA Works
- ----------------
-
- When the DA is launched for the first time, it starts at the root of
- the disk which contains the System folder, and does an HFS catalog
- of the entire disk. It finds each application on the disk, and
- stores the name and directory id in a special resource FILE called
- “Transfer data”, in the System folder. Henceforth, it uses this
- file to build the menu (the HFS catalog takes a little time - about
- 30 seconds on my 20 meg hard disk - so you wouldn't want to go
- through it every time).
-
- When an application is selected from the Transfer menu, the
- applications's name and directory id are copied into the DA's global
- data record, and the address of a special launch routine is
- installed in the “iaznotify” low-memory global. The transfer may
- be immediate or delayed; in the first case, the DA will call
- “ExitToShell”; in the second, it will wait for the application to
- quit normally.
-
- When the application quits, the Mac will prepare to launch the next
- application (usually the Finder). As one of the last steps in this
- process, it will call “InitApplZone” to initialize the heap. This
- trap will, in turn, call the routine whose address is stored in
- “iaznotify” - the DA's launch routine. This routine simply writes
- the name of the desired application to “curappname” (another low-
- memory global), and sets the directory to the proper directory.
- The Mac will then go ahead and launch the application. Sort of a
- cowbird launch, you might say!
-
- DA segmentation
- ---------------
-
- This is a small DA, a bit over 6K. so why is it segmented? Am I
- just showing off?
-
- Before “InitApplZone” calls the launch procedure, the Mac closes all
- resource files. That means that if the launch procedure is in a
- resource (e.g., the DRVR resource), it will be left in a free block.
- I don't feel very secure when executing code in a free block! The
- solution is to detach the resource; the block will remain allocated
- until “InitApplZone” actually cleans up the heap - which happens
- after it calls the launch routine.
-
- But if the launch routine is part of the DRVR resource, this means
- detaching the DRVR. If we do that, we'll never know about menu
- selections, since the desk Manager needs a DRVR resource to pass DA
- events to. so the launch routine has to be in a separate segment.
-
- The launch routine is in a PACK resource. The DRVR's “open” routine
- loads and locks the PACK, and records its address. when it wants to
- call a routine from the PACK, it puts a routine selector into
- register D0 and jumps to the PACK. At the top of the PACK is a jump
- table that branches to the routine corresponding to the selector.
-
- There are other ways to segment a DA; this is just the way I did
- this one.
-
- Creating Resources with TML Pascal
- ----------------------------------
-
- Since it came up in the May letters column, let me say a few words
- on this topic. It's really simple, once you know the (undocumented)
- trick. It's all in the link control file.
-
- For example, here is a link Control FILE to Create an LDEF:
-
- !fastlist
- /codetype LDEF 1001 'Fast List' 32
- list
- pas$library
- macintfglue
- /end
-
- The first line is the linker's start point - the name of the
- main routine. The second line defines the resource type. This
- will be an LDEF, resource id 1001, named “Fast List”, purgeable.
- The next three lines are the object files to link, in the order
- you want them to be linked. And the final line means just what
- it says.
-
- The code itself should be compiled as a unit, and most resource
- types will require that the main routine appear at the very top
- of the resource.
-
- The two resources in this program are linked a bit differently,
- the DRVR resource because the resource definition requires a
- DA header at the top, and the PACK resource because I want a
- jump table at the top. The fact that I left out the first Line
- and got away with it suggests that it may not be necessary.
-
- Using the DA
- ------------
-
- I have tested this DA with every application on my hard disk (at the
- time I wrote it). A number of application require the delayed
- transfer; for example, any program that uses scratch files. I found
- only one that would not work at all. Can you guess? That's right -
- Microsoft Word.
-
- Transfer vs. Multifinder
- ------------------------
-
- I leave as an exercise for the reader the problem of making this DA
- work with the Multifinder. A more fruitful project might be
- converting the DA to an FKEY.